using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Mark.Models;

/// <summary>
/// 消息实体
/// </summary>
public class Message : BaseEntity
{
    /// <summary>
    /// 消息内容
    /// </summary>
    [Required]
    public string Content { get; set; } = string.Empty;
    
    /// <summary>
    /// 消息角色：user, assistant, system
    /// </summary>
    [Required]
    [MaxLength(20)]
    public string Role { get; set; } = "user";
    
    /// <summary>
    /// 消息类型：text, image, file, function_call, etc.
    /// </summary>
    [MaxLength(50)]
    public string Type { get; set; } = "text";
    
    /// <summary>
    /// 消息状态：sent, delivered, error, generating
    /// </summary>
    [MaxLength(20)]
    public string Status { get; set; } = "sent";
    
    /// <summary>
    /// 消息元数据 (JSON)
    /// </summary>
    public string? Metadata { get; set; }
    
    /// <summary>
    /// Token数量
    /// </summary>
    public int? TokenCount { get; set; }
    
    /// <summary>
    /// 生成耗时（毫秒）
    /// </summary>
    public int? GenerationTime { get; set; }
    
    /// <summary>
    /// 错误信息
    /// </summary>
    [MaxLength(1000)]
    public string? Error { get; set; }
    
    /// <summary>
    /// 父消息ID（用于消息树结构）
    /// </summary>
    public string? ParentMessageId { get; set; }
    
    /// <summary>
    /// 消息序号
    /// </summary>
    public int SequenceNumber { get; set; }
    
    // 外键
    [Required]
    public string ConversationId { get; set; } = string.Empty;
    
    public string? ModelId { get; set; }
    
    // 导航属性
    [ForeignKey("ConversationId")]
    public virtual Conversation Conversation { get; set; } = null!;
    
    [ForeignKey("ModelId")]
    public virtual Model? Model { get; set; }
    
    [ForeignKey("ParentMessageId")]
    public virtual Message? ParentMessage { get; set; }
    
    public virtual ICollection<Message> ChildMessages { get; set; } = new List<Message>();
    
    public virtual ICollection<MessageFile> MessageFiles { get; set; } = new List<MessageFile>();
} 